/**
 * Created by fly on 2016/12/13.
 */
var webpack = require('webpack');
var commonsPlugin = new webpack.optimize.CommonsChunkPlugin('common.js');
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var path = require('path');
var WebpackDevServer = require("webpack-dev-server");

module.exports = {

    //页面入口文件配置
    entry: {
        index: './views/src/js/index.js'
        // 需要被提取为公共模块的群组
        // vendors:['component']
    },
    //入口文件输出配置
    output: {
        path: './public/dist/js',
        filename: "index.js"
    },
    watch:true,
    devServer:{
        historyApiFallback:true,
        hot:true,
        inline:true,
        progress:true,
        port:8080 //端口你可以自定义
    },
    vue:{
        loaders:{
            js:'babel'
        }
    },
    // 转化成es5的语法
    babel: {
        presets: ['es2015'],
        plugins: ['transform-runtime']
    },
    // 其他解决方案
    resolve: {
        // require时省略的扩展名，遇到.vue结尾的也要去加载
        extensions: ['','.js', '.vue'],
        // 模块别名地址，方便后续直接引用别名，无须写长长的地址，注意如果后续不能识别该别名，需要先设置root
        alias:{'vue':__dirname+'/node_modules/vue/dist/vue.js'}
    },
    module: {
        loaders: [
            // 使用vue-loader 加载 .component 结尾的文件
            {test: /\.js$/,loader: 'babel',exclude: /node_modules/},
            {test: /\.vue$/, loader: 'vue'},
            {test: /\.css$/, loader: 'style!css'},
            {test: /\.(jpg|png|gif)$/, loader: "url?limit=8192&name=../../images/[hash:8].[name].[ext]"},
            {test: path.join(__dirname, 'es6'), loader: 'babel-loader', query: {presets: ['es2015']}}
        ]
    },
    plugins: [
        new ExtractTextPlugin("./public/dist/[name].bundle.css",{allChunks: true})
    ]
};